package com.lesso.zgs.sunflower.infra.repository.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.zgs.sunflower.domain.repository.EmployeeAttendanceRuleRepository;
import com.lesso.zgs.sunflower.infra.mapper.EmployeeAttendanceRuleMapper;
import com.lesso.zgs.sunflower.model.EmployeeAttendanceRule;
import com.lesso.zgs.sunflower.pojo.dto.EmployeeAttendanceRuleQueryDTO;
import com.lesso.zgs.sunflower.pojo.vo.EmployeeAttendanceRuleVO;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

/**
 * EmployeeAttendanceRuleRepositoryImpl
 *
 * @author zgs
 * @since 2025-07-03
 */
@Repository
public class EmployeeAttendanceRuleRepositoryImpl implements EmployeeAttendanceRuleRepository {
    private final EmployeeAttendanceRuleMapper employeeAttendanceRuleMapper;

    public EmployeeAttendanceRuleRepositoryImpl(EmployeeAttendanceRuleMapper employeeAttendanceRuleMapper) {
        this.employeeAttendanceRuleMapper = employeeAttendanceRuleMapper;
    }

    @Override
    public Integer save(EmployeeAttendanceRule employeeAttendanceRule) {
        employeeAttendanceRuleMapper.insert(employeeAttendanceRule);
        return Math.toIntExact(employeeAttendanceRule.getId());
    }

    @Override
    public Integer delete(Long id) {
        return employeeAttendanceRuleMapper.deleteById(id);
    }

    @Override
    public Page<EmployeeAttendanceRuleVO> getPageList(EmployeeAttendanceRuleQueryDTO dto) {
        if (dto == null) {
            throw new IllegalArgumentException("EmployeeAttendanceRuleQueryDTO is null");
        }
        Page<EmployeeAttendanceRuleVO> page = new Page<>(dto.getCurrent(), dto.getSize());
        List<EmployeeAttendanceRuleVO> list = employeeAttendanceRuleMapper.selectPageList(page, dto);
        return page.setRecords(list);
    }

    @Override
    public List<EmployeeAttendanceRuleVO> getByEmployeeId(Long employeeId) {
        return employeeAttendanceRuleMapper.selectByEmployeeId(employeeId);
    }
} 